package com.itxiaoxiong.chat.service.impl;

import com.itxiaoxiong.chat.mapper.UserMapper;
import com.itxiaoxiong.chat.pojo.User;
import com.itxiaoxiong.chat.pojo.UserAccount;
import com.itxiaoxiong.chat.pojo.UserTT;
import com.itxiaoxiong.chat.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Resource
    private StringRedisTemplate stringRedisTemplate;
    @Autowired
    private UserMapper userMapper;

/*    @Override
    public List<UserTT> list() {
        return userMapper.list();
    }*/

/*    @Override
    public void delete(String account) {
        log.info("准备删除 account: {}", account);
        userMapper.deleteByAccount(account);
        log.info("删除操作执行完毕，account: {}", account);
    }*/

    @Override
    public boolean delete(String account) {
        int rowsDeleted = userMapper.deleteByAccount(account);
        if (rowsDeleted == 0) {
           // log.warn("未找到与账号 {} 匹配的记录，删除操作未生效", account);
            return false;
        }
        return true;
    }

    @Override
    public void add(User user) {

        userMapper.insert(user);
    }

    public boolean isUsernameExists(String username) {
        User existingUser = userMapper.findByUsername(username);
        return existingUser!= null;
    }

    @Override
    public void update(User user) {
        userMapper.update(user);
    }

/*    @Override
    public User listUserName(String username) {
        return userMapper.listUserName(username);
    }*/
    @Override
    public User listUserName(Integer id) {
        return userMapper.listUserName(id);
    }


//    @Override
//    public User userAccount(User user) {
//        return userMapper.accountUser(user);
//    }
    @Override
    public User userAccount(UserAccount ua) {
        return userMapper.accountUser(ua);
    }

}
